﻿using System;
using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdArticle.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdArticle;
/// <summary>
/// 添加文章服务
/// </summary>
public class InsertMdArticleService : ApiBase<RequestInsertMdArticleModel>
{
    /// <summary>
    /// 文章仓储
    /// </summary>
    public MdArticleRep mdArticleRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdArticleModel();

        model.Title = Parameter.Title;
        model.SubTitle = Parameter.SubTitle;
        model.SeoTitle = Parameter.SeoTitle;
        model.SeoDesc = Parameter.SeoDesc;
        model.SeoKeywork = Parameter.SeoKeywork;
        model.Cover = Parameter.Cover;
        model.ThumCover = Parameter.ThumCover;
        model.Description = Parameter.Description;
        model.Content = Parameter.Content;
        model.Author = Parameter.Author;
        model.Tag = Parameter.Tag;
        model.Files = Parameter.Files;
        model.VideoFiles = Parameter.VideoFiles;
        model.Link = Parameter.Link;
        model.IsExternalLink = Parameter.IsExternalLink;
        model.CategoryId = Parameter.CategoryId;
        model.ArticleType = Parameter.ArticleType;
        model.Status = Parameter.Status;
        model.DelFlag = "0";
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = mdArticleRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = mdArticleRep.GetMdArticleById(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

